/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import DAOInterface.DAOConnection;
import ModelInterface.IEventMap;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Fabian
 */
public class EventMap implements IEventMap {
    
    private DAOConnection myDAOsource;
    private DAOConnection myDAOtarget;
    private ArrayList columnas;

    /**
     * 
     * @param parametros
     */
    @Override
    public void createEvent(ArrayList parametros) {
        columnas = new ArrayList();
        columnas.add("subject");
        columnas.add("object");
        columnas.add("typeevent");
        columnas.add("time");
        this.myDAOtarget.createElement("event",columnas, parametros);
    }

    /**
     * 
     * @param conexionS
     */
    @Override
    public void setDAOSourceConnection(DAOConnection conexionS) {
        this.myDAOsource = conexionS;
    }

    /**
     * 
     * @param conexionT
     */
    @Override
    public void setDAOTargetConnection(DAOConnection conexionT) {
        myDAOtarget = conexionT;
    }

    /**
     * 
     * @param object
     * @param typeEvent
     * @return
     */
    @Override
    public String getIDevent(String object, String typeEvent) {
        ArrayList columnaID = new ArrayList();
        String pk = this.myDAOtarget.getPK("event");
        String query = "object = '" + object + "' AND typeEvent = '" + typeEvent +"'";
        columnaID.add(pk);
        String id = null;
        ResultSet rs = this.myDAOtarget.getElement("event", columnaID, query);
        try {
            while (rs.next()) {
                id = rs.getString(1);
            }
        } catch (SQLException ex) {
            Logger.getLogger(EventMap.class.getName()).log(Level.SEVERE, null, ex);
        }
        return id;
    }

    /**
     * 
     * @return
     */
    @Override
    public String getLastQuery() {
        return this.myDAOtarget.getLastQuery();
    }
    
}
